<template>
  <div class="bankAdd">
    <div>
      <jc-button
        :btn-arr="['reload', 'save', 'sub', 'remove', 'pass', 'list']"
        :disab-arr="[isDisabled && 'save', 'close', 'cancel', 'copy', 'com1', 'com2', 'using', 'freeze']"
        :list="'/cashAccountList'"
        @refresh="handelDetail"
        @save="save"
        @submit="save(1)"
        @noSubmit="submit(2)"
        @audit="audit(1)"
        @noAudit="audit(2)"
        @del="remove"
      />
    </div>
    <el-form :model="proValue" size="mini" label-width="100px">
      <el-form-item :label="$t('market.state')">
        <el-tag :type="proValue.stateColor">{{ proValue.fdocumentstatus }}</el-tag>
      </el-form-item>
      <!--      <el-form-item label="创建组织">-->
      <!--        <el-input v-model.trim="proValue.fcreateorgname" disabled />-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="使用组织">-->
      <!--        <el-input v-model.trim="proValue.fuseorgname" disabled />-->
      <!--      </el-form-item>-->
      <el-form-item :label="$t('menu.cashAccount')">
        <el-input v-model="proValue.fcashaccount" :disabled="isDisabled" />
      </el-form-item>
      <el-form-item :label="$t('market.accountname1')">
        <el-input v-model="proValue.faccountname" :disabled="isDisabled" />
      </el-form-item>
      <el-form-item :label="$t('market.defaultUser')">
        <el-input v-model.trim="proValue.fdefaultusername" :disabled="isDisabled">
          <i
            slot="suffix"
            class="el-input__icon el-icon-search"
            @click="departRenVisiblit=true"
          />
        </el-input>
      </el-form-item>
      <el-form-item :label="$t('market.note')">
        <el-input v-model="proValue.fremark" :disabled="isDisabled" />
      </el-form-item>
    </el-form>
    <!--员工-->
    <responRen v-if="departRenVisiblit" @depart="departData1" />
  </div>
</template>

<script>
import bility from '@/mixin/Operability'
import {
  deleteCashAccount,
  noreviewCashAccount,
  nosubmitCashAccount, queryCashAccountDetails,
  reviewCashAccount,
  submitCashAccount,
  updateCashAccount
} from '@/api/financial/teller'
import jcButton from '@/components/Button'
import { notoMxBmina, toMxBmina } from '@/components/ToMxamineState'

export default {
  name: 'CashAccountDetail',
  components: {
    jcButton,
    responRen: () => import('@/views/quality/qualityDetail/component/responRen')
  },
  mixins: [bility],
  data() {
    return {
      isDisabled: false,
      departRenVisiblit: false,
      proValue: {}
    }
  },
  created() {
    if (this.$route.params.id) {
      this.handelDetail()
    }
  },
  methods: {
    handelDetail() {
      const fcashaccountid = this.$route.params.id
      queryCashAccountDetails({ fcashaccountid }).then(res => {
        if (res.code === 0) {
          this.proValue = {
            ...toMxBmina(res.data)
          }
          this.isDisabled = this.proValue.fdocumentstatus === this.$t('market.state2') || this.proValue.fdocumentstatus === this.$t('market.state1')
        } else {
          this.$confirm(res.message, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'error'
          })
        }
      })
    },
    // 保存
    save(ev) {
      updateCashAccount(notoMxBmina(this.proValue)).then(res => {
        if (res.code === 0) {
          ev === 1 ? this.submit(1) : this.handelDetail()
          this.$message({ showClose: true, message: res.message, type: 'success' })
        } else {
          this.$confirm(res.message, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'error'
          })
        }
      })
    },
    // 币别
    departData1(ev) {
      if (ev.fuserId) {
        this.proValue.fdefaultusername = ev.fname
        this.proValue.fdefaultuserid = ev.fuserId
      }
      this.departRenVisiblit = false
    },
    // 公共函数
    toExamineFun(api) {
      const DATA = { Numbers: [this.proValue.fcashaccount] }
      api(DATA).then(res => {
        if (res.code !== 0) {
          this.$confirm(res.message, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'error'
          })
          return
        }
        this.handelDetail()
        this.selectVal = []
        this.innerHTM = ''
        res.data.forEach(res => {
          this.innerHTM += '<div>' + res + '</div>'
        })
        this.$notify.warning({
          title: '提示',
          message: this.innerHTM,
          duration: 3000, offset: 50,
          dangerouslyUseHTMLString: true
        })
      })
    },
    // 提交
    submit(ev) {
      const api = ev === 1 ? submitCashAccount : nosubmitCashAccount
      this.toExamineFun(api)
    },
    // 审核
    audit(ev) {
      const api = ev === 1 ? reviewCashAccount : noreviewCashAccount
      this.toExamineFun(api)
    },
    // 删除
    remove() {
      this.$confirm('确定要删除该订单么？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const api = deleteCashAccount
        const DATA = { Numbers: [this.proValue.fcashaccount] }
        api(DATA).then(res => {
          if (res.code !== 0) {
            this.$confirm(res.message, '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'error'
            })
            return
          }
          this.innerHTM = ''
          res.data.forEach(res => {
            this.innerHTM += '<div>' + res + '</div>'
          })
          this.$notify.warning({
            title: '提示',
            message: this.innerHTM,
            duration: 3000, offset: 50,
            dangerouslyUseHTMLString: true
          })
          // 关闭当前页面
          this.$store.dispatch('tagsView/guanbi', this.$route)
          this.$router.push({ path: '/cashAccountList' })
        })
      })
    }
  }
}
</script>

<style scoped lang="scss">
.bankAdd {
  @include listBom;
  background: #fff;
  .el-input::v-deep .el-input__inner {
    height: 30px;
    line-height: 30px;
  }
  .el-form {
    margin-top: 5px;
    //display: flex;
    flex-wrap: wrap;
    .el-form-item {
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      margin-bottom: 10px;
      .el-input {
        width: 180px;
      }
    }
  }
}
</style>

